﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Resources;
using System.Diagnostics;

using AdaptiveHelpDesk;                                         // Helpdesk function
using AdaptiveHelpDesk.AUI_Model_Components.Watcher.Combo_box;  // interaction techniques

namespace Novice
{
    [WebService(Namespace = "http://soaiui.nmmu.ac.za/")]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class SearchCustomer : System.Web.Services.WebService
    {

        #region VARIABLES ***********************************

        //Hashtable and arraylist used to load search results
        Hashtable ht = new Hashtable();
        ArrayList values = new ArrayList();

        //initialise stored procedures
        StoredProcedures sp = new StoredProcedures();

        //declare task model classes
        UpdateTaskModel updateTModel;
        GetTaskModel getTModel;

        //declare global method class
        GlobalMethods gMethods;


        //User details
        String user = "";
        String name = "";
        String surname = "";
        String stereotype = "";

        //Date and Time for User Profile
        String loggedDate = "";
        String loggedTime = "";


        #region IMSearchCustomer Variables

        //Total Time spent
        int totalTime = 0;

        //User Model Variables
        decimal totalTimeSearchCust = 0.0m;
        int yDistance = 0;
        int yDistanceCount = 1;
        decimal selectionTimeSearchCust = 0.0m;
        decimal selectionTimeTemp = 0.0m;
        int curMouseIndex = 0;
        decimal dTime = 0.0m;
        decimal dTimeParts = 0.0m;
        int nrItemsVisited = 0;
        Hashtable uniqueItemsHash = new Hashtable();

        //Class to get unique items
        InteractionTechnique interactTech = new InteractionTechnique();

        //Update User Model
        UpdateUserModelComboBox updateUserModelSearchCust;

        #endregion


        //Call ID
        String callID = "";

        Boolean isStepComplete = false;
        String incompleteStep = "";

        #endregion

        #region Emile :- User Details

        // Variables for UI elements to be created

        // View Selected Customer
        String userid;
        String firstname;
        String lastname;
        String email;
        String campus;
        String building;
        String roomNo;
        String ext;

        // Search Criteria
        String strSearchBy; //  String searchBy
        [Serializable]
        public enum searchBy { UserID, FirstName, LastName}
        
        String searchResults = "";

        // Search Results
        #endregion

        #region Emile:- Web Methods
        
        [WebMethod]
        public String Search(searchBy searchBy, String SearchValue) // maps to searchBy in bronwins form
        {
            StoredProcedures sp = new StoredProcedures();
            String str_searchBy = "";
            switch (searchBy)
            {
                case searchBy.UserID: str_searchBy = "UserID";
                    break;
                case searchBy.FirstName: str_searchBy = "FirstName"; 
                    break;
                case searchBy.LastName: str_searchBy = "LastName"; 
                    break;
            }

            ht = sp.getCustomer(str_searchBy, SearchValue);

            //if there are no results
            if (ht.Count == 0)
            {
                return "There are no customers with " + str_searchBy + " beginning with " + SearchValue;
            }

            return "complete";

        }
   
        #endregion
    }
}
